package com.autocar.reader.adapter;

import java.util.ArrayList;
import java.util.List;

import com.autocar.reader.R;
import com.autocar.reader.bean.WarnBean;
import com.autocar.reader.bean.XiaoxiBean;
import com.autocar.reader.util.ImageUtils;
import com.org.any.autocar.fragment.IAuthorClickListener;
import com.org.any.autocar.fragment.IopenAddFrends;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatSerchPopleInfoAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	List<XiaoxiBean> wlist = new ArrayList<XiaoxiBean>();
	private IAuthorClickListener authorClickListener = null;
	Bitmap bmp = null;

	public ChatSerchPopleInfoAdapter(Context context,
			IAuthorClickListener authorClickListener) {
		inflater = LayoutInflater.from(context);
		this.authorClickListener = authorClickListener;
		bmp = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.no_img_0);
	}

	public void setWList(List<XiaoxiBean> wlist1) {
		this.wlist.addAll(wlist1);
		if (wlist != null) {
			notifyDataSetChanged();
		}
	}
	
	public List<XiaoxiBean> getWList(){
		return wlist;
	}

	@Override
	public int getCount() {
		return wlist.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewHodler;
		if (convertView == null) {
			viewHodler = new ViewHodler();
			convertView = inflater.inflate(R.layout.chat_warn_item, null);
			viewHodler.nameTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_name);
			viewHodler.picIv = (ImageView) convertView
					.findViewById(R.id.chat_warn_item_iv_pic);
			viewHodler.timeTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_time);
			viewHodler.commentTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_comment);
			viewHodler.replyCmTv = (TextView) convertView
					.findViewById(R.id.chat_warn_item_tv_reply_comment);
			convertView.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) convertView.getTag();
		}
		final XiaoxiBean bean = wlist.get(position);
		viewHodler.nameTv.setText(bean.getUsername());
		viewHodler.timeTv.setText(bean.getAddtime());
		viewHodler.commentTv.setText(bean.getContent());
		viewHodler.picIv.setImageBitmap(null);
		ImageUtils.fb.display(viewHodler.picIv, bean.getPhoto(),bmp);
		Log.i("test", "phone2 : " + bean.getPhoto());
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				authorClickListener.toClick(bean);
			}
		});
		viewHodler.picIv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				authorClickListener.toAuthor(bean.getUid());
			}
		});
		convertView.setLongClickable(true);
		convertView.setOnLongClickListener(new OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				// TODO Auto-generated method stub
				authorClickListener.toLong(bean);
				return true;
			}
		});
		viewHodler.replyCmTv.setVisibility(View.GONE);
		return convertView;
	}

	class ViewHodler {
		TextView titleTv;
		TextView nameTv;
		TextView commentTv;
		TextView replyCmTv;
		TextView timeTv;
		ImageView picIv;
	}

}
